import React, { Component } from 'react';
import { Redirect } from 'react-router-dom'
class Beforeeach extends Component {
  render() {
    const { path, component: Comp, children, auth, alreadyLogin } = this.props
    const token = localStorage.getItem('token')
    // 根据路由表元信息auth 登录拦截
    if(!token && auth ) {
      return <Redirect to="/login"></Redirect>
    }
    // 根据路由表元信息alreadyLogin  登录重定向拦截
    if(alreadyLogin && token) {
      return <Redirect to="/"></Redirect>
    }

    return <Comp routes={ children } { ...this.props }/>
  }
}

export default Beforeeach;
